$(function() {
    $('form').parsley();
    dynamicBinding();
    getAllResExternal();
});
//遍历所有resExternal输出到表格
function getAllResExternal() {
    let deleteStr = "";
    let updateStr = "";
    let columns = [
        {title: "序号", data: null,"render": function (data,type,row,meta) {
                return data=Number(meta.row)+Number(1);
            }},
        {title: "应急医疗资源", data: "medical"},
        {title: "应急通信资源", data: "communication"},
        {title: "应急运输资源", data: "transport"},
        {title: "应急避难场所", data: "shelter"},
        {title: "操作", data: "id","orderable": false, // 禁用排序
            "defaultContent": "","render": function (data,type,row,meta) {
                if (hasDeletePermission) {
                    deleteStr = "<button data-id=" + data + "  type='button' class='btn btn-danger data-delete'>删除</button>&emsp;"
                }
                if (hasUpdatePermission) {
                    updateStr = "<button data-id=" + data + " type='button' class='btn btn-info data-update' data-toggle='modal' data-target='#updateResExternalModal'>更新</button>";
                }
                return data = deleteStr+updateStr;}}
    ];
    let url ='resExternal/getAllResExternal';
    dataTableInit(url,columns);
}
//动态绑定
function dynamicBinding() {
    //为所有的delete按钮绑定delete事件
    deleteBind( '/resExternal/deleteResExternal');
    //为所有的update按钮绑定update事件
    updateBind(  '#toUpdateResExternal', '/resExternal/updateResExternal', false, false, "#updateResExternalModal");
    //为所有的add按钮绑定add事件
    addBind('#toAddResExternal', '/resExternal/addResExternal', false, false, "#addResExternalModal");

    //为add模态框绑定消失事件-清空模态框中内容
    $('#addResExternalModal').on('hidden.bs.modal', function () {
        document.getElementById("toAddResExternal").reset();
    });
    //为update模态框绑定消失事件-清空模态框中内容
    $('#updateResExternalModal').on('hidden.bs.modal', function () {
        document.getElementById("toUpdateResExternal").reset();
    });
}
